package com.sdhs.myproject.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdhs.myproject.domain.GcMyprojectAssociatedUnit;
import com.sdhs.myproject.service.IGcMyprojectAssociatedUnitService;


/**
 * 我的项目--项目关联单位Controller
 *
 * @author andong
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/myproject/unit")
public class GcMyprojectAssociatedUnitController extends BaseController
{
    @Autowired
    private IGcMyprojectAssociatedUnitService gcMyprojectAssociatedUnitService;

    /**
     * 查询我的项目--项目关联单位列表
     */
    @PreAuthorize("@ss.hasPermi('myproject:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcMyprojectAssociatedUnit gcMyprojectAssociatedUnit)
    {
        startPage();
        List<GcMyprojectAssociatedUnit> list = gcMyprojectAssociatedUnitService.selectGcMyprojectAssociatedUnitList(gcMyprojectAssociatedUnit);
        return getDataTable(list);
    }

    /**
     * 导出我的项目--项目关联单位列表
     */
    @PreAuthorize("@ss.hasPermi('myproject:unit:export')")
    @Log(title = "我的项目--项目关联单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcMyprojectAssociatedUnit gcMyprojectAssociatedUnit)
    {
        List<GcMyprojectAssociatedUnit> list = gcMyprojectAssociatedUnitService.selectGcMyprojectAssociatedUnitList(gcMyprojectAssociatedUnit);
        ExcelUtil<GcMyprojectAssociatedUnit> util = new ExcelUtil<GcMyprojectAssociatedUnit>(GcMyprojectAssociatedUnit.class);
        util.exportExcel(response, list, "我的项目--项目关联单位数据");
    }

    /**
     * 获取我的项目--项目关联单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('myproject:unit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gcMyprojectAssociatedUnitService.selectGcMyprojectAssociatedUnitById(id));
    }

    /**
     * 新增我的项目--项目关联单位
     */
    @PreAuthorize("@ss.hasPermi('myproject:unit:add')")
    @Log(title = "我的项目--项目关联单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcMyprojectAssociatedUnit gcMyprojectAssociatedUnit)
    {
        return toAjax(gcMyprojectAssociatedUnitService.insertGcMyprojectAssociatedUnit(gcMyprojectAssociatedUnit));
    }

    /**
     * 修改我的项目--项目关联单位
     */
    @PreAuthorize("@ss.hasPermi('myproject:unit:edit')")
    @Log(title = "我的项目--项目关联单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcMyprojectAssociatedUnit gcMyprojectAssociatedUnit)
    {
        return toAjax(gcMyprojectAssociatedUnitService.updateGcMyprojectAssociatedUnit(gcMyprojectAssociatedUnit));
    }

    /**
     * 删除我的项目--项目关联单位
     */
    @PreAuthorize("@ss.hasPermi('myproject:unit:remove')")
    @Log(title = "我的项目--项目关联单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gcMyprojectAssociatedUnitService.deleteGcMyprojectAssociatedUnitByIds(ids));
    }
}
